/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cc.controller;

import cc.model.CurrencyDTO;
import cc.model.CurrencyRate2;
import cc.model.CurrencyRateKey;
import cc.model.Rate;
import cc.model.RatePK;
import cc.view.ConversionManager;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author zno
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@Stateless

public class ConverterFacade {
    @PersistenceContext(unitName ="HW4PU")
    
    private EntityManager em;

    
    
    public float convert(String id, String id0, float amount) {
        
        
        
        System.out.println("Value of id "+id+" value of id0 "+id0);
        
        //Rate rate=em.find(Rate.class, new RatePK (id, id0));
        RatePK key=new RatePK("USD","EUR");
        Rate rate=em.find(Rate.class, key);
        if(rate!=null){
            System.out.println("Rate is: "+rate.getRate());
            return amount*rate.getRate();
        }else
            return -99;
        
        
        
    }

    
    
    
    
    
    
}
